package com.tz.farmer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tz.farmer.model.FarmerSunData;
import com.tz.farmer.service.IFarmerSummaryService;
import com.tz.farmer.service.IFarmerSunDataService;
import com.tz.farmer.service.ISummaryService;
import com.tz.farmer.vo.SummaryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class SummaryServiceImpl implements ISummaryService {

    @Autowired
    private IFarmerSummaryService summaryService;

    @Autowired
    private IFarmerSunDataService dataService;

    @Override
    public SummaryVo getSummary(String market, String channel, String dataKey) {
        // 获取抽检信息
        SummaryVo response = summaryService.getFarmerSummary(market, channel);
        // 获取总任务数
        FarmerSunData one = dataService.getOne(new LambdaQueryWrapper<FarmerSunData>()
            .eq(FarmerSunData::getMarket, market)
            .eq(FarmerSunData::getCode, dataKey));

        if (one != null) response.setTotal(new BigDecimal(one.getValue().toString()).intValue());

        return response;
    }
}
